package vistas;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractAction;
import javax.swing.JButton;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import clases.Seccion;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class JDAplicarEvaluacion extends javax.swing.JDialog {
	private JPanel jPAplicarEvaluacion;
	private JButton jButtonAplicarEvaluacion;
	private AbstractAction abstractAction1;
	private AbstractAction abstractAction3;
	private AbstractAction abstractAction2;
	private JButton jButtonsalir;
	private JButton jButtonPromediar;
	private Seccion _seccion;
	/**
	* Auto-generated main method to display this JDialog
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				JDAplicarEvaluacion inst = new JDAplicarEvaluacion(frame,new Seccion());
				inst.setVisible(true);
			}
		});
	}
	
	public JDAplicarEvaluacion(JFrame frame,Seccion secion) {
		super(frame);
		initGUI();
		_seccion = secion;
	}
	
	
	private void initGUI() {
		try {
			setTitle("Evaluacion");
			{
				jPAplicarEvaluacion = new JPanel();
				getContentPane().add(jPAplicarEvaluacion, BorderLayout.CENTER);
				jPAplicarEvaluacion.setLayout(null);
				{
					jButtonAplicarEvaluacion = new JButton();
					jPAplicarEvaluacion.add(jButtonAplicarEvaluacion);
					jButtonAplicarEvaluacion.setText("Aplicar Las Evaluaciones");
					jButtonAplicarEvaluacion.setBounds(26, 43, 235, 34);
					jButtonAplicarEvaluacion.setAction(getAbstractAction1());
				}
				{
					jButtonPromediar = new JButton();
					jPAplicarEvaluacion.add(jButtonPromediar);
					jButtonPromediar.setText("Promediar");
					jButtonPromediar.setBounds(26, 122, 235, 32);
					jButtonPromediar.setAction(getAbstractAction2());
				}
				{
					jButtonsalir = new JButton();
					jPAplicarEvaluacion.add(jButtonsalir);
					jButtonsalir.setText("Volver");
					jButtonsalir.setBounds(269, 207, 81, 25);
					
					jButtonsalir.setFont(new java.awt.Font("DejaVu Serif",0,11));
					jButtonsalir.setAction(getAbstractAction3());
					jButtonsalir.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							System.out.println("jButtonsalir.actionPerformed, event="+evt);
							//TODO add your code for jButtonsalir.actionPerformed
	                      //  System.exit(0);					
						}
					});

				}
			}
			setSize(400, 300);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private AbstractAction getAbstractAction1() {
		if(abstractAction1 == null) {
			abstractAction1 = new AbstractAction("Aplicar", null) {
				public void actionPerformed(ActionEvent evt) {
					_seccion.aplicarEvaluaciones();
					JOptionPane.showMessageDialog(new JFrame(),"Evaluaciones aplicadas con exito","Evaluacion",JOptionPane.INFORMATION_MESSAGE);
					
				}
			};
		}
		return abstractAction1;
	}
	
	private AbstractAction getAbstractAction2() {
		if(abstractAction2 == null) {
			abstractAction2 = new AbstractAction("Promediar", null) {
				public void actionPerformed(ActionEvent evt) {
					if(_seccion.is_evaluacion())
						JOptionPane.showMessageDialog(new JFrame(),"El promedio de notas de la seccion es "+_seccion.generarPromedio(),"Evaluacion",JOptionPane.INFORMATION_MESSAGE);
					else
						JOptionPane.showMessageDialog(new JFrame(),"Debe aplicar las evaluaciones","Evaluacion",JOptionPane.WARNING_MESSAGE);
					
				 
				}
			};
		}
		return abstractAction2;
	}
	
	private AbstractAction getAbstractAction3() {
		if(abstractAction3 == null) {
			abstractAction3 = new AbstractAction("Volver", null) {
				public void actionPerformed(ActionEvent evt) {
					dispose();
				}
			};
		}
		return abstractAction3;
	}

}
